import axios from "axios";
const apiClient = axios.create({
  baseURL: 'http://127.0.0.1:8000',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
});

export const DeviceAPI = {
  getDevices: async () => {
    try {
      const response = await apiClient.get('/devices/devices');
      return response.data.map((device: any) => ({
        id: device.serial,
        name: device.serial
      }));
    } catch (error) {
      throw error;
    }
  },
  emulateDeviceClick: async (deviceId: string,x:number,y:number) => {
    try {
      const response = await apiClient.post('/devices/click', {device_id:deviceId, x, y });
      return response.data; 
    }
    catch (error) {
      throw error;
    }
  },
  emulateDeviceSwipe: async (deviceId: string,startX:number,startY:number,endX:number,endY:number) => {
    try {
      const response = await apiClient.post(`/devices/swipe`, {device_id:deviceId, 
        start_x: startX,
        start_y: startY,
        end_x: endX,
        end_y: endY ,
        duration:5
      });
      return response.data;
    }
    catch (error) {
      throw error;
    }
  }
};

